var express = require('express'); //引入框架
var db = require('./db.js')
var route = express.Router();

var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({
    extended: false
})

route.get('/get', function (req, res) {
    var sql = `select * from goods where tuijian=1 order by rand() limit 4`

    db.doMysql(sql).then(data => {
        res.send(db.backText(data))
    })
})

route.get('/getslider', function (req, res) {
    var sql = `select * from slider`

    db.doMysql(sql).then(data => {
        res.send(db.backText(data))
    })
})

route.get('/getitem', function (req, res) {
    var {
        uid
    } = req.query
    var sql = `select * from goods where id=${uid}`

    db.doMysql(sql).then(data => {
        res.send(db.backText(data))
    })
})

exports.route = route